package com.scsj.supermarket.view.activity.marketmodel;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.scsj.supermarket.R;
import com.scsj.supermarket.adapter.CouponAdapter;
import com.scsj.supermarket.base.MarketBase;
import com.scsj.supermarket.bean.BaseBean;
import com.scsj.supermarket.bean.MarketCouPounBean;
import com.scsj.supermarket.bean.MarketDetailBean;
import com.scsj.supermarket.bean.MarketRightBean;
import com.scsj.supermarket.bean.MarketShopCarBean;
import com.scsj.supermarket.presenter.MarketPresenter;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;
import com.scsj.supermarket.view.fragment.couponmodel.CouponUnused;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import java.util.ArrayList;
import es.dmoral.toasty.Toasty;


/**
 * 商家店铺详情
 */
public class MarketActivity extends BaseActivity implements MarketBase.IView {
    
    private CouponUnused couponUnused;
    private LinearLayout market_main_ll;
    private CouponAdapter couponAdapter;
    private ArrayList<String> couponList;
    private RecyclerView market_coupon_rv;
    private MarketPresenter presenter;
    private ImageView mBackIv;
    /**
     * 雀巢咖啡套餐
     */
    private AutoCompleteTextView mSearchAt;
    private LinearLayout mSerchLl;
    private ImageView mCollectIv;
    private ImageView mSettingIv;
    private ImageView mShopIconIv;
    /**
     * 商超世界CBD店
     */
    private TextView mMarketNameTv;
    /**
     * 欢迎光临商超世界CBD店
     */
    private TextView mShopIntroTv;
    /**
     * 已保
     */
    private TextView mIndexType1Tv;
    /**
     * 实体店
     */
    private TextView mIndexType2Tv;
    /**
     * 商超专送
     */
    private TextView mIndexType3Tv;
    /**
     * 满减
     */
    private TextView mReduceTv;
    /**
     * 全场满50减30，满50减30，满50减30
     */
    private TextView mShopContentTv;
    private LinearLayout mTitleLl;
    private RecyclerView mMarketCouponRv;
    /**
     * 商品种类：15643
     */
    private TextView mGoodsNumTv;
    /**
     * 月销单量：1564单
     */
    private TextView mMonthNumTv;
    /**
     * 收藏人数：15643人
     */
    private TextView mCollectPersonTv;
    /**
     * 营业时间：15：20 - 22:30
     */
    private TextView mShopTimeTv;
    /**
     * 商家配送：0元起送，配送费3元
     */
    private TextView mSendTypeTv;
    /**
     * 店铺地址：路劲大厦15号
     */
    private TextView mShopAdressTv;
    /**
     * 商家电话：1144245643
     */
    private TextView mShopTelTv;
    private LinearLayout mCommScoreLl;
    private LinearLayout mAllCommNumLl;
    /**
     * 查看用戶所有评价
     */
    private TextView mSeeAllCommTv;
    private LinearLayout mUpToGoLl;
    private LinearLayout mMarketMainLl;
    private LinearLayout turn_down_ll;
    private SlidingUpPanelLayout mLayout;
    private android.app.Fragment marketFragment;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_market);
        marketFragment = getFragmentManager().findFragmentById(R.id.market_fg);

//        presenter = new MarketPresenter(this);
//        JSONObject jsonObject3 = new JSONObject();
//        jsonObject3.put("id", "dianpu1");
//        RequestBody body3 = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), jsonObject3.toString());
//        presenter.deliverMarketCoupounList(body3);
//
//        JSONObject jsonObject1 = new JSONObject();
//        jsonObject1.put("id", "3cad7a54-79d4-11e8-afb7-70106fb15682");
//        jsonObject1.put("userId", "1");
//        RequestBody body1 = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), jsonObject1.toString());
//        presenter.deliverMarketDetailList(body1);

        initView();
        initListener();
        initData();
    }

    @Override
    protected void initView() {

        mLayout = findViewById(R.id.sliding_layout);
        mLayout.setAnchorPoint(1.0f);
        mLayout.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);

        market_main_ll = findViewById(R.id.market_main_ll);
        market_coupon_rv = findViewById(R.id.market_coupon_rv);
        market_coupon_rv.setLayoutManager(new LinearLayoutManager(this));
        market_coupon_rv.setNestedScrollingEnabled(false);
        mBackIv = (ImageView) findViewById(R.id.back_iv);
        mSearchAt = (AutoCompleteTextView) findViewById(R.id.search_at);
        mSerchLl = (LinearLayout) findViewById(R.id.serch_ll);
        mCollectIv = (ImageView) findViewById(R.id.collect_iv);
        mSettingIv = (ImageView) findViewById(R.id.setting_iv);
        mShopIconIv = (ImageView) findViewById(R.id.shop_icon_iv);
        mMarketNameTv = (TextView) findViewById(R.id.market_name_tv);
        mShopIntroTv = (TextView) findViewById(R.id.shop_intro_tv);
        mIndexType1Tv = (TextView) findViewById(R.id.index_type1_tv);
        mIndexType2Tv = (TextView) findViewById(R.id.index_type2_tv);
        mIndexType3Tv = (TextView) findViewById(R.id.index_type3_tv);
        mReduceTv = (TextView) findViewById(R.id.reduce_tv);
        mShopContentTv = (TextView) findViewById(R.id.shop_content_tv);
        mTitleLl = (LinearLayout) findViewById(R.id.title_ll);
        mMarketCouponRv = (RecyclerView) findViewById(R.id.market_coupon_rv);
        mGoodsNumTv = (TextView) findViewById(R.id.goods_num_tv);
        mMonthNumTv = (TextView) findViewById(R.id.month_num_tv);
        mCollectPersonTv = (TextView) findViewById(R.id.collect_person_tv);
        mShopTimeTv = (TextView) findViewById(R.id.shop_time_tv);
        mSendTypeTv = (TextView) findViewById(R.id.send_type_tv);
        mShopAdressTv = (TextView) findViewById(R.id.shop_adress_tv);
        mShopTelTv = (TextView) findViewById(R.id.shop_tel_tv);
        mCommScoreLl = (LinearLayout) findViewById(R.id.comm_score_ll);
        mAllCommNumLl = (LinearLayout) findViewById(R.id.all_comm_num_ll);
        mSeeAllCommTv = (TextView) findViewById(R.id.see_all_comm_tv);
        mUpToGoLl = (LinearLayout) findViewById(R.id.up_to_go_ll);
        mMarketMainLl = (LinearLayout) findViewById(R.id.market_main_ll);
        turn_down_ll = findViewById(R.id.turn_down_ll);

    }

    @Override
    protected void initListener() {
//        if (mLayout != null) {
//            if (mLayout.getAnchorPoint() == 1.0f) {
//                mLayout.setAnchorPoint(1.0f);
//                mLayout.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);
//
//            } else {
//                mLayout.setAnchorPoint(1.0f);
//                mLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
//
//            }
//        }
    }

    @Override
    protected void initData() {


    }

    @Override
    public void showSuccessMsg(String s) {
        Toasty.success(mContext, s).show();
    }

    @Override
    public void showErrorMsg(String s) {
        Toasty.error(mContext, s).show();
    }

    @Override
    public void setMarketShopCarData(MarketShopCarBean marketShopCarData) {

    }

    @Override
    public void controlMarketShopCarData(BaseBean baseBean) {

    }

    @Override
    public void setMarketDetailData(MarketDetailBean marketDetailData) {
        Glide.with(mContext).load(marketDetailData.getData().getAppHeadStoreVo().getResourceInfos().get(0).getUrlFrameCapture());
        mMarketNameTv.setText(marketDetailData.getData().getAppHeadStoreVo().getStores().getName());
        mShopIntroTv.setText(marketDetailData.getData().getAppHeadStoreVo().getStores().getNotice());
    }

    @Override
    public void setMarketCoupounData(MarketCouPounBean marketCoupounData) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < marketCoupounData.getData().getDiscountcoupon().size(); i++) {
            arrayList.add(marketCoupounData.getData().getDiscountcoupon().get(i).getName());
        }
        couponAdapter = new CouponAdapter(this, arrayList, 0);
        market_coupon_rv.setAdapter(couponAdapter);
    }

    @Override
    public void setMarketRightData(MarketRightBean marketRightBean) {

    }
}
